﻿using System;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using System.Diagnostics.CodeAnalysis;
using iTeamyou.LTS.UI.Models;
using iTeamyou.LTS.Core.Services;

namespace iTeamyou.LTS.UI.Shared.Components
{
    public partial class ProductLicenseSearch
    {
        /// <summary>
        /// 
        /// </summary>
        [Parameter]
        [NotNull]
        public ProductSearchModel? Value { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Parameter]
        public EventCallback<ProductSearchModel> ValueChanged { get; set; }

        public List<SelectedItem> LicenseTypeList { get; set; }

        [Inject]
        [NotNull]
        private ProductService? ProductService { get; set; } = new();

        public ProductLicenseSearch()
        {
            GetLicenseTypes();
        }

        private void GetLicenseTypes()
        {
            var licenseTypes = ProductService.GetLicenseType("product");
            if (licenseTypes != null && licenseTypes.Any())
            {
                LicenseTypeList = new List<SelectedItem>() { new SelectedItem() { Text = "请选择 ...", Value = string.Empty } };
                foreach (var type in licenseTypes)
                {
                    LicenseTypeList.Add(new SelectedItem() { Text = type.TypeName, Value = type.TypeId });
                }
            }
        }
    }
}

